package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.presentation.controller.user.devicedata;

import java.util.ArrayList;
import java.util.List;

import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.AlarmService;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.AlarmService.AlarmState;

/**
 * 
 * Este Bean es utilizado en las vistas
 * simpleuser/devicedata.xhtml
 * simpleuser/alarms.xhtml
 */
public class AlarmBean {

	private AlarmService alarmServ;
	
	public AlarmBean(AlarmService al) {
		alarmServ = al;
	}
	public String getDevname(){
		return alarmServ.getDeviceAlarmName();
	}
	public String getName(){
		return alarmServ.getAlarmName();
	}
	public String getField(){
		return alarmServ.getFieldName();
	}
	public String getValue(){
		try{
			
			Integer ret = alarmServ.getFieldValue();
			if(ret == null)
				return "devicedata.alarm.value.novalue";
			return ret.toString();
		}
		catch(Exception e){
		return 	"devicedata.field.value.novalue";
		}
	}
	public String getCriteria(){
		return alarmServ.getAlarmCriteria();
		
	}
	public String getState(){
		try
		{
			AlarmState st = alarmServ.getState();
			if(st == AlarmState.ON)
				return "devicedata.alarm.state.on";
			return "devicedata.alarm.state.off";
		}
		catch(Exception e){
		return 	"devicedata.field.value.novalue";
		}
	}
	public static List<AlarmBean> wrap(List<AlarmService> deviceAlarmsService) {
		ArrayList<AlarmBean> ret = new ArrayList<AlarmBean>();
		for(AlarmService al: deviceAlarmsService){
			ret.add(new AlarmBean(al));
		}
		return ret;
	}

}
